﻿@model CodeFarmer.Model.Entities.User
@{
    ViewBag.Title = "新用户注册 - 码农中国";
}
<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script type="text/javascript">
    function RefreshCode() {
        $("#AhthenCode").attr("src", '@Url.Action("Generate", "AuthenCode")');
    }
    $(document).ready(function () {
        $("#AhthenCode").bind("click", RefreshCode);
        var validateOpts = {
            rules: {
                Email: {
                    required: true,
                    email: true,
                    remote: {
                        url: '@Url.Action("CheckEmail")',
                        type: "post",
                        data: {
                            mail: function () {
                                return $('#Email').val();
                            }
                        }
                    }
                },
                UserName: {
                    required: true,
                    minlength: 2,
                    remote: {
                        url: '@Url.Action("CheckUserName")',
                        type: "post",
                        data: {
                            mail: function () {
                                return $('#UserName').val();
                            }
                        }
                    }
                },
                NickName: {
                    required: true,
                    minlength: 2,
                    remote: {
                        url: '@Url.Action("CheckNickName")',
                        type: "post",
                        data: {
                            mail: function () {
                                return $('#NickName').val();
                            }
                        }
                    }
                },
                PassWord: {
                    required: true,
                    minlength: 4
                },
                RePassWord: {
                    required: true,
                    equalTo: "#PassWord"
                },
                AuthenCode: {
                    required: true,
                    remote: {
                        url: '@Url.Action("CheckAuthenCode")',
                        type: "post",
                        data: {
                            code: function () {
                                return $('#AuthenCode').val();
                            }
                        }
                    }
                }
            },
            messages: {
                Email: {
                    required: "不可为空",
                    email: "请输入正确格式的电子邮件",
                    remote: "该邮箱已被注册"
                },
                UserName: {
                    required: "不可为空",
                    minlength: "用户名长度不小于2",
                    remote: "该用户名已被注册"
                },
                NickName: {
                    required: "不可为空",
                    minlength: "昵称长度不小于2",
                    remote: "该昵称已被注册"
                },
                PassWord: {
                    required: "不可为空",
                    minlength: "密码长度至少要4位"
                },
                RePassWord: {
                    required: "不可为空",
                    equalTo: "两次输入密码必须相同"
                },
                AuthenCode: {
                    required: "不可为空",
                    remote: "验证码错误"
                }
            },
            success: function (label) {
                label.html("").addClass("success");
            }


        };
        $('#regForm').validate(validateOpts);
    })

</script>
<link href="@Url.Content("~/Resources/Skin/Default/style.css")" rel="stylesheet" type="text/css" />
@using (Html.BeginForm("Register", "UserCenter", FormMethod.Post, new { id = "regForm" }))
{
    <fieldset>
        <legend style="font-size: larger">欢迎您的注册(锄禾日当午,Coding最辛苦) </legend>
        <div>
            <table>
                <tr>
                    <td>
                        邮箱:
                    </td>
                    <td>@Html.TextBoxFor(m => m.Email)
                    </td>
                </tr>
                <tr>
                    <td>
                        用户名:
                    </td>
                    <td>@Html.TextBoxFor(m => m.UserName)
                    </td>
                </tr>
                <tr>
                    <td>
                        昵称:
                    </td>
                    <td>@Html.TextBoxFor(m => m.NickName)
                    </td>
                </tr>
                <tr>
                    <td>
                        密码:
                    </td>
                    <td>@Html.PasswordFor(m => m.PassWord)
                    </td>
                </tr>
                <tr>
                    <td>
                        确认密码:
                    </td>
                    <td>@Html.Password("RePassWord")
                    </td>
                </tr>
                <tr>
                    <td>
                        验证码:
                    </td>
                    <td>
                        @Html.TextBox("AuthenCode")&nbsp;
                        <img id="AhthenCode" alt="验证码" style="cursor: pointer;" src="@Url.Action("Generate", "AuthenCode")"/>
                        <a href="javascript:void(0);" onclick="RefreshCode();return false;">看不清，换一张</a>
                    </td>
                </tr>
            </table>
            <div>
                <input type="submit" value="注册" />
            </div>
        </div>
    </fieldset>
}
